#FROM openjdk:8-jdk
#ARG BUILD_PROFILE
#LABEL maintainer=lancelotsheng


#ENV PARAMS="--server.port=8080 --spring.profiles.active=${BUILD_PROFILE} --spring.cloud.nacos.discovery.server-addr=ruoyi-nacos.ruoyi:8848 --spring.cloud.nacos.config.server-addr=ruoyi-nacos.ruoyi:8848 --spring.cloud.nacos.config.namespace=ruoyi-ctg-prod --spring.cloud.nacos.config.file-extension=yml"
#RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone

#COPY target/*.jar /app.jar
#EXPOSE 8080

#ENTRYPOINT ["/bin/sh","-c","java -Dfile.encoding=utf8 -Djava.security.egd=file:/dev/./urandom -jar app.jar ${PARAMS}"]


FROM openjdk:8-jdk as builder
LABEL maintainer=leifengyang
WORKDIR application
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
COPY target/*.jar application.jar
RUN java -Djarmode=layertools -jar application.jar extract

FROM openjdk:8-jdk
ARG BUILD_PROFILE
#ARG不能用在ENTRYPOINT里，ENV才可以
ENV PROFILE1=$BUILD_PROFILE
WORKDIR application
#ENV PARAMS="--server.port=8080 --spring.profiles.active=${BUILD_PROFILE} --spring.cloud.nacos.discovery.server-addr=ruoyi-nacos.ruoyi:8848 --spring.cloud.nacos.config.server-addr=ruoyi-nacos.ruoyi:8848 --spring.cloud.nacos.config.namespace=ruoyi-ctg-${BUILD_PROFILE} --spring.cloud.nacos.config.file-extension=yml"

EXPOSE 8080
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/application/ ./


ENTRYPOINT ["java","-Dserver.port=8080","-Dspring.profiles.active=${PROFILE1}","-Dspring.cloud.nacos.discovery.server-addr=ruoyi-nacos.ruoyi:8848","-Dspring.cloud.nacos.config.server-addr=ruoyi-nacos.ruoyi:8848","-Dspring.cloud.nacos.config.namespace=ruoyi-ctg-${PROFILE1}","-Dspring.cloud.nacos.config.file-extension=yml","org.springframework.boot.loader.JarLauncher"]
#ENTRYPOINT ["/bin/sh","-c","java -Dfile.encoding=utf8 -Djava.security.egd=file:/dev/./urandom org.springframework.boot.loader.JarLauncher"]

